<template>
  <div class="wrap">
    <h3>修改密码</h3>

    <div class="content" v-show="show">
      <div class="iphoneCode">
        <input class="inp" @blur="yzIphone()" v-model="iphone"  type="text" placeholder="请输入手机号">
        <img v-if="iphoneTrue" src="../../../static/login/check .png" height="12" width="12"/>
      </div>

      <p class="false">
        <span v-if="bol"><img src="../../../static/login/alert.png" alt="">手机号码不正确,请重新输入</span>
      </p>

      <input class="inp"  v-model="password" type="password" placeholder="请输入密码（6-20位号码字符）"><br>
      <input class="inp repwd" v-model="repassword" type="password" placeholder="请再次输入密码确认">

      <div class="clearfix yzm">
        <input class="inp-yzm" v-model="code" type="text" placeholder="验证码">
        <Code class="code" ref="zi"></Code>
      </div>

      <div class="iphoneyzm">
        <input class="inp" :disabled="dis1" v-model="iphoneyzm"  type="text" placeholder="手机验证码">
        <button @click="getCode()" :class="yzm?'yzmbtn':'aa'" :disabled='dis2'>
          {{tit}}
        </button>
      </div>
      <button class="btn3" @click="xiugai">提交修改</button>


      <div class="showDiv" v-if="showdiv" @click="hideDiv()">
        <img src="../../../static/zwf/mine/dui.png" />
        <span>恭喜您修改成功</span>
      </div>
    </div>
    <p class="pp" v-show="show1">暂无数据,请登录</p>

  </div>
</template>

<script>
  import Code from '../com/Code'
  import axios from 'axios'
    export default {
        name: "Changepwd",
      data(){
          return{
            iphoneTrue:false,
            bol:false,
            showimg:true,
            dis:true,
            dis1:true,
            dis2:false,
            iphone:'',
            password:'',
            repassword:'',
            iphoneyzm:'',
            code:'',
            yzm:true,
            iphonecode:'',
            tit:'获取验证码',
            num:60,
            showdiv:false,
            show:true,
            show1:false
          }
      },
      components:{
        Code
      },
      methods:{
        yzIphone(){
          var reg=/^1[34578]\d{9}$/;
          if(!reg.test(this.iphone)){
            this.bol=true;
            this.iphoneTrue=false;
            // this.iphone='';
            return false;
          }else{
            this.bol=false;
            this.iphoneTrue=true;
          }
        },
        getCode(){
          this.yzm=false;
          this.dis2=true;
          this.dis1=false;
          this.iphonecode=1111;
          this.tit=this.num+'s';
          var timmer= setInterval(function(){
            this.num--;
            this.tit=this.num+'s';
            if(this.num==0){
              clearInterval(timmer);
              this.yzm=true;
              this.dis2=false;
              this.tit='获取验证码';
              this.num=3;
            }
          }.bind(this),1000)
        },
        show(){
          this.showimg=false;
          this.dis=false;
        },
        hide(){
          this.showimg=true;
          this.dis=true;
        },
        xiugai(){
          if(this.iphone.trim()==''){
            alert('手机号不能为空');
            return false;
          }
          if(this.password.trim()==''){
            alert('密码不能为空');
            return false;
          }
          if(this.repassword.trim()==''){
            alert('确认密码不能为空');
            return false;
          }
          if(this.code != this.$refs.zi.str2){
            alert('验证码不正确,请重新输入')
            this.$refs.zi.changeImg();
            this.code='';
            return false;
          }else if(this.iphoneyzm!=this.iphonecode){
            if(this.iphoneyzm.trim()==''){
              alert('验证码不能为空');
              return false;
            }else{
              alert('手机验证码不正确,请重新输入');
              return false;
            }
          }else{
            var params=new URLSearchParams();
            params.append('iphone',this.iphone);
            params.append('pwd',this.password);
            params.append('repwd',this.repassword);

            axios.post('/api/firday/respassword.php',params).then(res=>{
              if(res.data.code==1){
                this.showdiv=true;
              }
            })
          }
        },
        hideDiv(){
          this.showdiv=false;
        }
      },
      mounted(){
          this.iphone=this.$store.state.phone;
        if(this.$store.state.phone==''){
          this.show=false;
          this.show1=true;
        }else{
          this.show=true;
          this.show1=false;
        }
      }
    }
</script>

<style scoped>
  .wrap{
    width: 1083px;
    height: 623px;
    border: 1px solid #e7e7e7;
  }
  .wrap h3{
    width: 1063px;
    height: 56px;
    line-height: 56px;
    padding-left: 20px;
    font-size: 18px;
    color: #212121;
    border-bottom: 1px solid #e7e7e7;
  }
  .content{
    position: relative;
    padding: 40px;
  }
  .iphoneCode{
    position: relative;
    width: 305px;
    height: 40px;
  }
  .iphoneCode img{
    position: absolute;
    top: 16px;
    right: 16px;
  }
  .inp{
    width: 281px;
    height: 16px;
    border: 1px solid #d3d3d3;
    padding:12px;
    font-size: 16px;
    background: #f9f9f9;
  }


  .repwd{
    margin-top: 30px;
  }

  .iphoneyzm{
    position: relative;
    width: 305px;
    height: 18px;
    margin-top: 30px;
    margin-bottom: 30px;
    background: red;
  }
  .iphoneyzm .yzmbtn{
    position: absolute;
    top: 5px;
    right: 10px;
    width: 100px;
    height: 30px;
    font-size: 14px;
    border-radius: 0;
    background: #498e3d;
    color: #fff;
  }
  .iphoneyzm .aa{
    position: absolute;
    top: 5px;
    right: 10px;
    width: 100px;
    height: 30px;
    font-size: 14px;
    border-radius: 0;
    background: #f2f2f2;
    color: #999;
  }

  .false{
    width: 305px;
    height: 30px;
    line-height: 30px;
  }
  .false span{
    color: #db2630;
  }
  .false span>img{
    width: 13px;
    height: 13px;
    margin-right: 5px;
    vertical-align: middle;
  }
  .yzm{
    display: flex;
    justify-content: space-between;
    width: 305px;
    height: 44px;
    padding-top: 30px;
  }

  .inp-yzm{
    width: 60px;
    height: 16px;
    padding:12px;
    border: 1px solid #d3d3d3;
    font-size: 16px;
    background: #f9f9f9;
    float: left;
  }
  .code{
    float: right;
    height: 40px;
  }

  .btn3{
    width: 150px;
    height: 50px;
    font-size: 18px;
    color: #fff;
    background: #f08200;
    border-radius: 5px;
    margin-top: 40px;
  }



  .showDiv{
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    background: #d9d9d9;
    width: 456px;
    height: 46px;
    border-radius: 20px;
    padding: 70px 0;
    text-align: center;
  }
  .showDiv span{
    font-size: 24px;
    line-height: 46px;
    color: #f08200;
    margin-left: 20px;
  }
  .showDiv img{
    vertical-align: bottom;
  }

  .pp{
    width: 1083px;
    height: 46px;
    line-height: 46px;
    border-bottom: 1px solid #e9e9e9;
    text-align: center;
  }
</style>
